package com.cea.papyrustest.uml.deletecommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;
import com.cea.papyrus.core.commands.UMLElementDeleteCommand;

/**
 * Test class for {@link Stereotype} deletion command
 * @author Remi Schnekenburger
 */
public class StereotypeDeleteCommandTest extends PapyrusCommandTest{

	/** name of the created element */
	protected final String NAME = "Stereotype_0";
	
	protected org.eclipse.uml2.uml.Profile profile;
	
	/**
	 * Default constructor
	 * @param name the name oif the test case
	 */
	public StereotypeDeleteCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Profile.class,model);
		stack.execute(papyrusCommand);
		// profile is created!
		profile=(Profile)((UMLElementCreateCommand)papyrusCommand).getElement();
		
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Stereotype.class, profile);
		stack.execute(papyrusCommand);
		Stereotype stereotype = (Stereotype)((UMLElementCreateCommand)papyrusCommand).getElement();
		assertNotNull("stereotype is null", stereotype);
		
		papyrusCommand = new UMLElementDeleteCommand(stereotype, profile);
		
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		assertNull("the stereotype exist!",profile.getPackagedElement(NAME));
		
		// undo
		stack.undo();
		Element clazz= profile.getPackagedElement(NAME);
		assertNotNull("the stereotype is created",clazz);
		assertTrue("this is not a stereotype",((clazz)instanceof Stereotype));
		
		
		// redo
		stack.redo();
		assertNull("the stereotype exist!",profile.getPackagedElement(NAME));
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrustest.uml.deletecommand.PapyrusCommandTest#tearDown()
	 */
	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
		papyrusCommand = new UMLElementDeleteCommand(profile, profile.getOwner());
		papyrusCommand.execute();
	}
}
